package org.extreme.schooltalk.parsing;

import java.io.InputStream;

import org.extreme.schooltalk.CommonUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class ParserOnlyResult extends DefaultHandler {
	private final String _RESULT = "result";
	private static final String _TAG = CommonUtils._LOG_TAG;
	private boolean inItem = false;
	private String rgt_msg = "false";
	
	public ParserOnlyResult(InputStream input){
		try {
			new SaxHandler(this,input);			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String getResult(){
		return rgt_msg;
	}
	public Boolean getResultBoolean(){
		return Boolean.valueOf(rgt_msg);
	}
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {			
		super.characters(ch, start, length);
		String content = new String(ch,start,length);
		//Log.i(_TAG,"content : "+content);
		if(inItem)
			rgt_msg = content;
	}

	@Override
	public void endDocument() throws SAXException {
		//Log.i(_TAG,"end Docs");
		super.endDocument();
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		//Log.i(_TAG,"end element");
		super.endElement(uri, localName, qName);
		if(inItem)
			inItem = false;
	}

	@Override
	public void startDocument() throws SAXException {
		//Log.i(_TAG,"start Docs");		
		super.startDocument();
		
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		//Log.i(_TAG,"start Element");
		super.startElement(uri, localName, qName, attributes);
		if(localName.equalsIgnoreCase(_RESULT)){
			inItem = true;
		}
	}
}
